//
//  SKUitilTool.swift
//  ScarnKing
//
//  Created by ninebot on 2025/7/22.
//

import Foundation
import UIKit

class SKUitilTool: NSObject {
    static var `default`:SKUitilTool = SKUitilTool()
    // 将图像转换为 Base64 编码字符串
    func convertImageToBase64(_ image: UIImage) -> String? {
        guard let imageData = image.jpegData(compressionQuality: 0.1) else { return nil }
        return imageData.base64EncodedString(options: [])
    }
    
    func convertBase64ToImage(base64String: String) -> UIImage? {
        guard let imageData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters) else {
            return nil
        }
        return UIImage(data: imageData)
    }
    
    func getAttributeString(_ string: String,lineSpace:CGFloat
        ) -> NSAttributedString{
        let attributedString = NSMutableAttributedString(string: string)
        let paragraphStye = NSMutableParagraphStyle()

        //调整行间距
        paragraphStye.lineSpacing = lineSpace
        let rang = NSMakeRange(0, CFStringGetLength(string as CFString?))
        attributedString .addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStye, range: rang)
        return attributedString

    }
}
